using System;
using System.IO;
using System.Xml.Parser;
using System.Xml;
using System.Windows;
using System.Windows.Forms;
using System.Collections;
using Care.AAD;

namespace System.Xml.Parser.Demo
{


	class MyApp
	{
		[STAThread]
		static void Mainsherjil(string[] args)
		{
			MyApp iMyApp = new MyApp();/*
			//string ForwardMessage_XmlClass = XmlElement_2_XmlClass_Genrator.GenrateClass( "ForwardMessage", "category,key,priority,msgnum,submsg,after,lifetime".Split(new char[]{','}));
			//Console.WriteLine(ForwardMessage_XmlClass);
			string taglist =	"configuration,connections,connection,key,servername,databasename,username,password,"+
								"messagequeue,messageque,name,quepath,commchannels,modemchannel,comport,baudrate,simno,"+
								"communicationdirection,serviceprovider,reinitinterval,servermode,satchannel,sendingchannel," + 
								"recievingchannel";
			string paramlist =	", , , , , , , , , , , , , , , , , , , , , , ,";
			//string [] xyz = paramlist .Split(new char[]{','});
			string ForwardMessage_XmlClass = Xml2ClassGenrator.Xml2ClassGenrator.GenrateClasses(taglist.Split(new char[]{','}), paramlist.Split(new char[]{','}));
			Console.WriteLine(ForwardMessage_XmlClass);
*/
			//Type t = System.Type.GetType("System.Xml.Parser.XmlParser");
			//IXmlParser XmlParser1 = (IXmlParser)Activator.CreateInstance(t);

			
            //XmlParser XmlParser1 = (XmlParser)XmlParser.CreateInstance(); 
            //XmlParser1.XmlLoad( "configuration.xml", "");
            //Type t = System.Type.GetType("System.Xml." + XmlParser1.RootElementName + ".Xml" + XmlParser1.RootElementName + "");
            //XmlParser1.XmlParse(t.Assembly.FullName);
			
			//XmlSubmitMessage xmlsm = ((XmlSubmitMessage)XmlParser1.RootElement);
			//IEnumerator Enum = xmlsm.XmlAuthentications.Values.GetEnumerator();
			//while(Enum.MoveNext())
			//{
			//	XmlAuthentication XmlA = ((XmlAuthentication)Enum.Current);
			//	MessageBox.Show(XmlA.Name);
			//}
			
			//XmlParser1.XmlSave(Application.StartupPath + @"\xmlfiles\", false, "MyXmlFile.xml");
		}

		public static bool WriteFile(string Path, bool IsRelative, string FileName, string Data)
		{
			if(!Directory.Exists(Path))
				Directory.CreateDirectory(Path);
			if(DeleteFile(Path, IsRelative, FileName))
			{
				Path = IsRelative ? Application.StartupPath + Path : Path ;
				FileStream fileStream = new FileStream( Path + FileName, FileMode.OpenOrCreate, FileAccess.Write );
				StreamWriter Writer = new StreamWriter(fileStream);
				Writer.Write(Data);
				Writer.Flush();
				Writer.Close();
				return true;
			}
			else
				return false;
		}

		public static bool DeleteFile(string Path, bool IsRelative, string FileName)
		{
			Path = IsRelative ? Application.StartupPath + Path : Path;
			string AbsPath = Path;
			if(Directory.Exists(AbsPath))
			{
				FileInfo fi = new FileInfo(AbsPath + FileName);
				if(fi.Exists)
					fi.Delete();
				return true;
			}
			return false;
		}

	}
}
